package com.smart_campus.teg.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.vo.NoticeVo;
import com.smart_campus.teg.vo.MajorVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.teg.domain.Major;
import com.smart_campus.teg.mapper.MajorMapper;
import com.smart_campus.teg.service.MajorService;

import java.util.List;

/**
*   @aytgor 陈鹏
*   @date 2020/6/18 16:53
*
*/
@Service
public class MajorServiceImpl implements MajorService{

    @Resource
    private MajorMapper majorMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.teg.service.impl.MajorServiceImpl",key = "#majorId")
    @Override
    public int deleteByPrimaryKey(Integer majorId) {
        return majorMapper.deleteByPrimaryKey(majorId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.MajorServiceImpl",key = "#result.majorId")
    @Override
    public Major insert(Major record) {
        majorMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.MajorServiceImpl",key = "#result.majorId")
    @Override
    public Major insertSelective(Major record) {
        majorMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.teg.service.impl.MajorServiceImpl",key = "#majorId")
    @Override
    public Major selectByPrimaryKey(Integer majorId) {
        return majorMapper.selectByPrimaryKey(majorId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.MajorServiceImpl",key = "#result.majorId")
    @Override
    public Major updateByPrimaryKeySelective(Major record) {
        majorMapper.updateByPrimaryKeySelective(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.MajorServiceImpl",key = "#result.majorId")
    @Override
    public Major updateByPrimaryKey(Major record) {
        majorMapper.updateByPrimaryKey(record);
        return record;
    }

    @Override
    public DataGridView MajorList(MajorVo majorVo) {
        Page<Object> page = PageHelper.startPage(majorVo.getPage(), majorVo.getLimit());//分页数据格式
        List<Major> noticeVos = majorMapper.MajorList(majorVo);//返回的全部数据
        return new DataGridView(page.getTotal(), noticeVos);
    }

}
